#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
const int maxL = 131075;
int t;
char s[maxL];

// 分治思想
int check(int l,int r,char c){
    if(l == r) return s[l] != c;
    int tl = 0, tr = 0;

    int mid = (l + r) /2;

    for(int i = l; i<=mid; i++)if(s[i] != c)tl ++;
    for(int i = mid + 1; i<=r; i++)if(s[i] != c)tr ++;

    tl += check(mid+1,r,c+1);
    tr += check(l,mid,c+1);

    return min(tl,tr);
}





int main()
{
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        // scanf("%s",s+1);
      for(int i = 1; i<=n;i++)cin >> s[i];
      cout << check(1,n,'a') <<'\n';
    }
   
   return 0;
}
